Page({
    data: {
        productList:[
            {imageUrl:"../../image/lvyou@2x.png",title:"中联6012原厂标准节80节标",time:"2019-07-11",address:'湖北武汉',money:16.32},
            {imageUrl:"../../image/lvyou@2x.png",title:"中联6012原厂标准节80节标",time:"2019-07-11",address:'湖北武汉',money:16.32},
            {imageUrl:"../../image/lvyou@2x.png",title:"中联6012原厂标准节80节标",time:"2019-07-11",address:'湖北武汉',money:16.32},
            {imageUrl:"../../image/lvyou@2x.png",title:"中联6012原厂标准节80节标",time:"2019-07-11",address:'湖北武汉',money:16.32},
            {imageUrl:"../../image/lvyou@2x.png",title:"中联6012原厂标准节80节标",time:"2019-07-11",address:'湖北武汉',money:16.32}
        ],
        arr:[],
        selectType:'shebei',
        showShebei:true,
        showTiezi:false,
        userheaderImageList:{},
        pageObj:{},
        isGuanzhu:0,
        pageNum:1,
        current:1,
        pagesize:20,
        pages:1
    },
    //上拉加载更多
    onReachBottom:function(){
        console.log('加载更多')
        this.setData({
          current:this.data.current+1
        })
         if (this.data.current<=this.data.pages) {
          if (this.data.showShebei) {
                 this.getMySheBei();
             
          }else{
                 this.getMyTiezi();
          }
         }  
    },
    onLoad: function(options) {
        console.log(options)
        console.log("options.id="+options.id)
        if (options.type) {
            this.setData({
                type:123
            })
        }
      
        console.log(123)
            if (options.id) {
                 this.setData({
                id:options.id,
                // type:options.type
                })
            }else if(options.openid){
                 this.setData({
                openid:options.openid,
                // type:options.type
                }) 
            }
            getApp().getUserInfo().then(res=>{
                 var userInfo= wx.getStorageSync('userInfo');
                this.setData({
                    userInfo:userInfo
                })
               this.getAllMember();
               

            })

    },
    getMyTiezi:function () {
         var _self=this;
         wx.request({
            url:getApp().globalData.baseUrl+'/wx/articles/getList?status=20&openid='+this.data.openid+'&current='+this.data.current+'&pagesize='+this.data.pagesize,
            method:"GET",
            header: {
                'openid':this.data.userInfo.openid, //公用请求头
                'content-type': 'application/json'
            },
            success: function(res) {
           
             console.log(res)
             _self.setData({
                arr:_self.data.arr.concat(res.data.obj.list),
                 pages:res.data.obj.pages
             })
             
         }
     })
    },
    getMySheBei:function () {
         var _self=this;
         wx.request({
            url:getApp().globalData.baseUrl+'/wx/equipment/publish/getList?status=20&openid='+this.data.openid+'&current='+this.data.current+'&pagesize='+this.data.pagesize,
            method:"GET",
            header: {
                'openid':this.data.userInfo.openid, //公用请求头
                'content-type': 'application/json'
            },
            success: function(res) {
           
             console.log(res)
             _self.setData({
                productList:_self.data.productList.concat(res.data.obj.list),
                pages:res.data.obj.pages
             })
             
         }
     })
            
    },
     getAllMember:function () {
       
     
      var _self=this;
       _self.getMemberInfo();   
       _self.isGuanzhu();
       _self.getMySheBei();
       _self.getMyTiezi();
       //   wx.request({
       //      url: getApp().globalData.baseUrl +'/wx/user/champion/num?openid='+this.data.openid,
       //      method:"GET",
       //      header: {
       //          'openid':this.data.openid, //公用请求头
       //          'content-type': 'application/json'
       //      },
       //      success: function(res) {
       //          console.log(res.data.obj)
       //          _self.setData({
       //              userheaderImageList:{
       //                  wxUser:{
       //                      openid:_self.data.openid,
       //                      nickName:res.data.obj.nickName,
       //                      avatarUrl:res.data.obj.avatarUrl
       //                  }
       //              }
       //          })
             
            
       //   }
       // })

    },
    getMemberInfo:function () {
         var _self=this;
         wx.request({
            url: getApp().globalData.baseUrl +'/wx/user/champion/num?openid='+this.data.openid,
            method:"GET",
            header: {
                'openid':this.data.userInfo.openid, //公用请求头
                'content-type': 'application/json'
            },
            success: function(res) {
                console.log('**********')
             console.log(res.data.obj)
             _self.setData({
                pageObj:res.data.obj
            })
            
         }
       })

    },
    isGuanzhu:function (argument) {
        var userInfo= wx.getStorageSync('userInfo');
        var _self=this;
         wx.request({
            url: getApp().globalData.baseUrl +'/wx/follow/user?openid='+userInfo.openid+'&followOpenid='+this.data.openid,
            method:"GET",
            header: {
                'openid':this.data.userInfo.openid, //公用请求头
                'content-type': 'application/json'
            },
            success: function(res) {
             console.log(res.data.obj)
             _self.setData({
                isGuanzhu:res.data.obj
             })
            
         }
       }) 
    },
    onReady: function() {
        // 生命周期函数--监听页面初次渲染完成

    },
    onShow: function() {
        // 生命周期函数--监听页面显示


    },
    detailClick (e) {
        console.log(e.currentTarget.dataset.code)
       var id=e.currentTarget.dataset.code;
      wx.navigateTo({
        url: '/pages/deviceDetail/deviceDetail?id='+id,
      })
    },
     callPhone:function(){
        return
        console.log(12323)
        wx.makePhoneCall({
          phoneNumber: '13400000000' //仅为示例，并非真实的电话号码
        })
    },
    chooseType:function(e){
       var type=e.currentTarget.dataset.type
        console.log(type)
        var _self=this;
        this.setData({
         selectType:type,
         arr:[],
         productList:[],
         current:1
       })
         
            
       if (type=='shebei') {
         console.log('shebei')
       this.setData({
         showShebei:true,
         showTiezi:false
       })
        this.getMySheBei();
       }else if(type=='tiezi'){
         console.log('tiezi')
       this.setData({
        showTiezi:true,
        showShebei:false
       })
        this.getMyTiezi();
       }
       
       
    },
    guanZhu:function () {
        var userInfo= wx.getStorageSync('userInfo');
        var _self=this;
        var url,type,num;
        if (this.data.isGuanzhu==1) {
        url='/wx/follow/user/delete';
        type='DELETE';
        num=0;
        }else if(this.data.isGuanzhu==0){
         url='/wx/follow/user/save';
         type='GET';
         num=1;
        }
         wx.request({
            url: getApp().globalData.baseUrl +url+'?openid='+userInfo.openid+'&followOpenid='+this.data.openid,
            method:type,
            header: {
                'openid':this.data.userInfo.openid, //公用请求头
                'content-type': 'application/json'
            },
            success: function(res) {
             console.log(res.data.obj)
             if (res.data.code==200) {

                _self.setData({
                    isGuanzhu:num
                })
             }
            
            
         }
       }) 
    },
    turnDetail:function (e) {
       console.log(e.currentTarget.dataset.code)
        wx.navigateTo({
            url: '/pages/communityDetail/communityDetail?id='+e.currentTarget.dataset.code
        })
    },
    onShareAppMessage:function(){
         return {
              title: '我正在塔塔二手机开店铺卖设备，没有中间商赚差价',
              query:'openid='+this.data.openid+"&type=share",
              path: '/pages/eredarDetail/eredarDetail?openid='+this.data.openid+"&type=share"
            }
    },
     turnPage:function(){
        if (this.data.type) {

           wx.switchTab({
                  url: '../../pages/home/home'
           })
           return
        }
       
    },
})